package com.wgl.yygh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wgl.model.user.UserInfo;
import com.wgl.model.vo.user.UserInfoQueryVo;
import com.wgl.yygh.result.Result;
import com.wgl.yygh.serivice.UserInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author wgl
 * @version 1.0.0
 * @ClassName UserController.java
 * @Description TODO
 * @createTime 2022年02月12日 19:53:00
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Resource
    private UserInfoService userInfoService;
    /**
    * @Author: Wgl
    * @Description: 管理员查询所有的用户
    * @Date: 2022/2/12 23:03;
    * @param page:
     * @param limit:
     * @param userInfoQueryVo: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Integer page, @PathVariable Integer limit, UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page1 = new Page<>(page,limit);
        IPage<UserInfo> userInfoList = userInfoService.selectPage(page1,userInfoQueryVo);
        return Result.ok(userInfoList);
    }
    /**
    * @Author: Wgl
    * @Description: 锁定/解锁用户
    * @Date: 2022/2/12 23:04;
    * @param userId:
     * @param status: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("/lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId,@PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }

    /**
    * @Author: Wgl
    * @Description: 查询用户详情
    * @Date: 2022/2/12 23:14;
    * @param userId: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);

        return Result.ok(map);
    }
    /**
    * @Author: Wgl
    * @Description: 审核用户
    * @Date: 2022/2/12 23:30;
    * @param userId:
     * @param authStatus: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result approval(@PathVariable  Long userId,@PathVariable Integer authStatus ){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
